﻿/************************************************************************************
 * xujiajun@yoozoo.com 御剑
 * 展示指定显示元素的命令
 ***********************************************************************************/

using System;
using WorldMapBase.Tile;
using WorldMapBase.Tile.Pool;

namespace WorldMapBase.Display
{
    /// <summary>
    /// 展示指定显示元素的命令
    /// </summary>
    internal class ShowCommand : DisplayCommand
    {
        private int m_MapLayer;
        private int m_ResID;
        private int m_lodIndex;

        private CommandTileElement m_tileElement;

        protected override void OnExecute(DisplayElementFactory factory)
        {
            var element = factory.CreateDisplayElement(m_lodIndex,m_MapLayer,m_ResID);
            if (element != null)
            {
                if (m_tileElement != null)
                {
                    m_tileElement.SetDisplayElement(element);
                    m_tileElement.RefreshElementData(m_MapLayer);
                }
            }    
            else
            {
                m_tileElement.RegisterLoadCallBack();
            }
            
#if UNITY_EDITOR
            TileDisplayManager.OnShowElement(m_ResID);
#endif
        }

        protected internal override int GetResID()
        {
            return m_ResID;
        }

        /// <summary>
        /// 设置展示命令需要的数据
        /// </summary>
        /// <param name="resID">资源ID</param>
        /// <param name="callback">命令执行完毕的回调</param>
        internal void SetData(int lodIndex,int mapLayer,int resID, CommandTileElement tileElement)
        {
            m_lodIndex = lodIndex;
            m_MapLayer = mapLayer;
            m_ResID = resID;
            m_tileElement = tileElement;
        }
    }

}

